import requests from "./request";

import store from "@/store";
import request from "@/store/request";
import { data, param } from "jquery";
/**
 *注册
 * @param {*} param0 {username:用户名 password：密码 repassword：确认密码}
 * @returns
 */
export const registerAPI = ({ username, password, repassword }) =>
  requests({
    url: "/api/reg",
    method: "POST",
    data: {
      username,
      password,
      repassword,
    },
  });

/**
 *
 *登录
 * @param {} param0  username 用户名 passeord 密码
 * @returns token
 */
export const loginAPI = ({ username, password }) =>
  requests({
    url: "/api/login",
    method: "POST",
    data: {
      username,
      password,
    },
  });

/**
 * 登录后获取用户信息
 * @returns Promise
 */
export const getUserInfoAPI = () =>
  requests({
    url: "/my/userinfo",
    method: "get",
    // headers: {
    //   Authorization: store.state.users.token,
    // },
  });

/**
 * 用户信息更新
 * @param {username nickname  email user_pic age sign gender} data
 * @returns
 */
export const updateUserInfoAPI = (data) =>
  requests({
    url: "/my/userinfo",
    method: "post",
    data,
  });

/**
 *  更新密码
 * @param {oldPwd newPwd } param0
 * @returns
 */
export const updatePwdAPI = ({ newPwd, oldPwd }) =>
  requests({
    url: "/my/updatepwd",
    method: "post",
    data: {
      newPwd,
      oldPwd,
    },
  });

/**
 *发布留言
 * @param {message ,img_url} data
 */

export const addWallAPI = (data) =>
  requests({
    url: "/my/addWall",
    method: "post",
    data,
  });

/**
 * 获取留言卡片
 * @returns  promise
 */
export const getWallAPI = () =>
  requests({
    url: "/my/getWall",
    method: "get",
  });

/**
 * 获取个人留言  token 带id
 * @returns  promise
 */
export const getMyWallAPI = () =>
  requests({
    url: "/my/getMyWall",
    method: "get",
  });

/**
 *  删除个人留言卡片  传卡片  id
 * @param {params id} id
 * @returns
 */
export const deleteMyWallAPI = (id) =>
  requests({
    url: `/my/deletemywall`,
    method: "delete",
    params: {
      id,
    },
  });

/**
 * 点赞 id 卡片id
 * @returns promise { }
 */
export const updateWallLikeAPI = ({ wall_id }) =>
  requests({
    url: "/my/updateWallLike",
    method: "post",
    data: { wall_id },
  });

/**
 *  id 获取个人信息
 * @param {用户id} user_id
 */

export const findUserInfoAPI = (user_id) =>
  requests({
    url: `/my/finduserinfo/:user_id`,
    method: "get",
    params: {
      user_id,
    },
  });

/**
 * 
// 查询点赞的wall_id 红心显示
 * @returns Promise 
 */
export const findUserWallLikeAPI = () =>
  requests({
    url: "/my/findUserWallLike",
  });

// 评论页
/**
 * 发布评论
 * @param {wall_id,message} data
 * @returns  promise
 */
export const addWallCommentsAPI = (data) =>
  requests({
    url: "/my/addwallcomment",
    method: "post",
    data,
  });
/**
 * 获取该卡片所有评论
 * @param {wall_id} param0
 * @returns username ,message,user_pic ,moment
 */
// 注意get发不了body
export const getWallCommentsAPI = (wall_id) =>
  requests({
    url: "/my/getwallcomment",
    method: "get",
    params: {
      wall_id,
    },
  });

// 提问页
/**
 * 发布问题
 * @param {{title ,message}}
 * @returns
 */
export const addReqAPI = (data) =>
  requests({
    url: "/my/addreq",
    method: "post",
    data,
  });

/**获取所有未被删除卡片
 * way 1 为模糊查询
 * text 模糊查询内容
 * @param {way text} way
 * @param {*} text
 * @returns   request
 */
export const getReqAPI = ({ way, text }) =>
  requests({
    url: "/my/getreq",
    method: "get",
    params: { way, text },
  });

/**
 *
 * @returns promise request
 */
export const getMyReqAPI = () =>
  requests({
    url: "/my/getmyreq",
    method: "get",
  });

/**
 *
 * @param {删除reqId} req_id
 * @returns
 */
export const deleteMyReqAPI = (req_id) =>
  requests({
    url: "/my/myreq",
    method: "delete",
    params: {
      req_id,
    },
  });

/**
 * 我浏览过的问题
 * @param {*} req
 * @param {*} res
 * @returns  request
 */
export const findMyViewReqAPI = () =>
  requests({
    url: "/my/findmyviewreq",
    method: "get",
  });

//问题评论页

// router.post("/addwallcomment", reqComments_handler.addReqComments);
// router.get("/getwallcomment", reqComments_handler.getReqComments);
/**
 * 发布问题评论
 * @param {request_id message} param0
 * @returns
 */
export const addReqCommentsAPI = ({ request_id, message }) =>
  requests({
    url: "/my/addreqcomment",
    method: "post",
    data: {
      request_id,
      message,
    },
  });

/**
 * 获取每个卡片的评论
 * @param {request_id} request_id
 * @returns comment message like_num  moment username
 */
export const getReqCommentsAPI = (request_id) =>
  requests({
    url: "/my/getreqcomment",
    method: "get",
    params: {
      request_id,
    },
  });

/**
 * 更新提问的点击量
 * @param {request_id} request_id
 * @returns
 */
export const updateReqViewAPI = (request_id) =>
  requests({
    url: "/my/updatereqview",
    method: "post",
    params: {
      request_id,
    },
  });

/**
 * 
// 查询点赞的reqCom_id红心显示
 * @returns Promise 
 */
export const findUserReqComLikeAPI = () =>
  requests({
    method: "get",
    url: "/my/finduserreqcomlike",
  });

/**
 * 点赞的 问题卡片 评论卡片id
 * @returns promise { }
 */
export const updateReqComLikeAPI = ({ comment_id }) =>
  requests({
    url: "/my/updatereqcomLike",
    method: "post",
    data: { comment_id },
  });

// goods失物品招领接口

/**
 * 发布认领卡
 * @param {message img_url} param0
 * @returns
 */
export const addGetGoodsAPI = ({ message, img_url }) =>
  requests({
    url: "/my/addgetgoods",
    method: "post",
    data: { message, img_url },
  });

/**
 *获取认领卡
 * @param {*} param0
 * @returns  message img_url user_pic
 */
// export const getGoodsAPI = () =>
//   request({
//     url: "/my/getgoods",
//     method: "get",
//   });

export const getGoodsAPI = () =>
  requests({
    url: "/my/getgoods",
    method: "get",
  });

//发布求助卡

/**
 *
 * @param {message img_url} param0
 * @returns
 */
export const addHelpGoodsAPI = ({ message, img_url }) =>
  requests({
    url: "/my/addhelpgoods",
    method: "post",
    data: {
      message,
      img_url,
    },
  });

// 获取求助卡

export const getHelpGoodsAPI = () =>
  requests({
    url: "/my/gethelpgoods",
    method: "get",
  });

// 获取我的求助卡
/**
 *
 * @param {*} param0
 * @returns  Promise lost_help
 */
export const getMyHelpGoodsAPI = () =>
  requests({
    url: "/my/getmyhelpgoods",
    method: "get",
  });

//删除个人求助卡片
/** losthelp_id
 * return
 */
export const deleteMyHelpGoodsAPI = (losthelp_id) =>
  requests({
    method: "delete",
    url: "/my/myhelpgoods",
    params: {
      losthelp_id,
    },
  });

/**
 *更新find失物信息
 * @param {lostfind_id ,code} param0
 */
export const updateFindGoodsAPI = ({ lostfind_id, code }) =>
  requests({
    method: "post",
    url: "/my/updatefindgoods",
    data: {
      lostfind_id,
      code,
    },
  });

/**
 * 发表求助卡片留言
 * @param {lost_id message} param0
 */

export const addHelpGoodsCommentAPI = ({ lost_id, message }) =>
  requests({
    method: "post",
    url: "/my/addhelpgoodscomment",
    data: {
      lost_id,
      message,
    },
  });

/**
 *获取求助卡留言
 * @param {lost_id} param0
 * return {username messaeg, user_pic, moment}
 */
export const getHelpGoodsCommentAPI = (lost_id) =>
  requests({
    method: "get",
    url: "/my/gethelpgoodscomment",
    params: {
      lost_id,
    },
  });

/**
 *  发布 闲置卡片
 * @param {} param0
 * @returns
 */
export const addBuysAPI = ({ message, img_url, price, room_id }) =>
  requests({
    method: "post",
    url: "/my/addbuygoods",
    data: {
      message,
      img_url,
      price,
      room_id,
    },
  });

/**
 *
 * @returns 获取所有闲置卡
 */
export const getBuysAPI = () =>
  requests({
    method: "get",
    url: "/my/getbuys",
  });

/**
 *
 * @returns 获取我的闲置卡片
 */

export const getMyBuysAPI = () =>
  requests({
    method: "get",
    url: "/my/getmybuys",
  });

/**
 *
 * @param {删除我的闲置} buy_id
 * @returns
 */

export const deleteMyBuysAPI = (buy_id) =>
  requests({
    method: "delete",
    url: "/my/mybuys",
    params: {
      buy_id,
    },
  });
/**
 *
 * @param {更新闲置状态  1 为 已出 0 为未出} param0
 * @returns
 */

export const updateBusAPI = ({ code, losthelp_id }) =>
  requests({
    method: "post",
    url: "/my/updatebuys",
    data: {
      code,
      losthelp_id,
    },
  });

/**
 *
 * @returns 获取用户个人的评论及其评论卡的相关信息
 */
export const getMyComReqAPI = () =>
  requests({
    method: "get",
    url: "/my/getmycomreq",
  });

/**
 * com_id
 * @returns
 */
export const delteMyComAPI = (com_id) =>
  requests({
    method: "delete",
    url: "/my/deltemycom",
    params: {
      com_id,
    },
  });
